package crudfx.sound;
import javafx.animation.*;
/**
 * <p>Single drum</p>
 * <p><b>Example</b>
 * <i>Play quarter note of Acoustic Snare</i></p>
 * <pre>
package testbox;

import javafx.stage.*;
import javafx.scene.*;
import crudfx.control.*;
import crudfx.interop.*;
import crudfx.sound.*;

Stage{
    width:400
    height:400
    scene:Scene{
        content:UINode{
            content:StandardButton{
                text:"Play"
                action:function():Void{
                    Drum{
                        instrument:38
                        velocity:1
                        tempo:120
                        part:4
                        }.play(120);
                    }
                }
            }
        }
    }
 </pre>
 * @profile desktop
 * @author Sergey Surikov
 */
public class Drum {
    /**
    35-81
    */
    public var instrument:Number=0;//35-81
    /**
    0.0 - 1.0
    */
    public var velocity:Number=1;//0-1
    /**
    Part of whole note ie 16=sixteenth note
    */
    public var part:Number=4;
    /**
    Play
    */
    public function play(playTempo:Number):Void{
        var tempo:Number=playTempo;
        if(instrument<35 or instrument>81)instrument=35;
        MIDI.openDrum(instrument,127*velocity);
        if(part<=1)part=4;
        if(tempo<=0)tempo=120;
        Timeline{
            keyFrames:KeyFrame{
                time:Duration.valueOf((240*1000.0/tempo)/part)
                action:function():Void{
                    MIDI.closeDrum(instrument);
                    }
                }
            }.play();
        }
    }
